/// `POST /_matrix/identity/*/validate/email/requestToken`
///
/// Create a session for validating an email.
use crate::{OwnedClientSecret, OwnedSessionId};
use crate::{OwnedClientSecret, OwnedSessionId};
/// `/v2/` ([spec])
///
/// [spec]: https://spec.matrix.org/latest/identity-service-api/#post_matrixidentityv2validateemailrequesttoken

// const METADATA: Metadata = metadata! {
//     method: POST,
//     rate_limited: false,
//     authentication: AccessToken,
//     history: {
//         1.0 => "/_matrix/identity/v2/validate/email/requestToken",
//     }
// };

/// Request type for the `create_email_validation_session` endpoint.

#[derive(ToSchema, Deserialize, Debug)]
pub struct CreateEmailValidationSessionReqBody {
    /// A unique string generated by the client, and used to identify the validation attempt.
    pub client_secret: OwnedClientSecret,

    /// The email address to validate.
    pub email: String,

    /// The server will only send an email if the send_attempt is a number greater than the
    /// most recent one which it has seen, scoped to that email + client_secret pair.
    pub send_attempt: u64,

    /// When the validation is completed, the identity server will redirect the user to this
    /// URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_link: Option<String>,
}

/// Response type for the `create_email_validation_session` endpoint.
#[derive(ToSchema,Serialize, Debug)]
pub struct CreateEmailValidationSessionResBody {
    /// The session ID.
    ///
    /// Session IDs are opaque strings generated by the identity server.
    pub sid: OwnedSessionId,
}
impl CreateEmailValidationSessionResBody {
    /// Create a new `Response` with the given session ID.
    pub fn new(sid: OwnedSessionId) -> Self {
        Self { sid }
    }
}

/// `GET /_matrix/identity/*/validate/email/submitToken`
///
/// Validate ownership of an email ID by the end-user, after creation of a session.
/// `/v2/` ([spec])
///
/// [spec]: https://spec.matrix.org/latest/identity-service-api/#get_matrixidentityv2validateemailsubmittoken

// const METADATA: Metadata = metadata! {
//     method: GET,
//     rate_limited: false,
//     authentication: AccessToken,
//     history: {
//         1.0 => "/_matrix/identity/v2/validate/email/submitToken",
//     }
// };

/// Request type for the `validate_email_by_end_user` endpoint.
#[derive(ToParameters, Deserialize, Debug)]
pub struct ValidateEmailByEndUserReqArgs {
    /// The session ID, generated by the `requestToken` call.
    #[salvo(parameter(parameter_in = Query))]
    pub sid: OwnedSessionId,

    /// The client secret that was supplied to the `requestToken` call.
    #[salvo(parameter(parameter_in = Query))]
    pub client_secret: OwnedClientSecret,

    /// The token generated by the `requestToken` call and emailed to the user.
    #[salvo(parameter(parameter_in = Query))]
    pub token: String,
}

/// `POST /_matrix/identity/*/validate/email/submitToken`
///
/// Validate an email ID after creation of a session.
/// `/v2/` ([spec])
///
/// [spec]: https://spec.matrix.org/latest/identity-service-api/#post_matrixidentityv2validateemailsubmittoken

// const METADATA: Metadata = metadata! {
//     method: POST,
//     rate_limited: false,
//     authentication: AccessToken,
//     history: {
//         1.0 => "/_matrix/identity/v2/validate/email/submitToken",
//     }
// };

/// Request type for the `validate_email` endpoint.

#[derive(ToSchema, Deserialize, Debug)]
pub struct ValidateEmailReqBody {
    /// The session ID, generated by the `requestToken` call.
    pub sid: OwnedSessionId,

    /// The client secret that was supplied to the `requestToken` call.
    pub client_secret: OwnedClientSecret,

    /// The token generated by the `requestToken` call and emailed to the user.
    pub token: String,
}

/// Response type for the `validate_email` endpoint.
#[derive(ToSchema,Serialize, Debug)]
pub struct ValidateEmailResBody {
    /// Whether the validation was successful or not.
    pub success: bool,
}
impl ValidateEmailResBody {
    /// Create a new `Response` with the success status.
    pub fn new(success: bool) -> Self {
        Self { success }
    }
}
